package com.zygk.library.base;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.OnClick;
import com.zygk.library.R;
import com.zygk.library.R2;
import com.zygk.library.util.ToastUtil;
import com.zygk.library.view.ProgressWebView;

import static com.zygk.library.util.Util.isNetworkAvailable;

/**
 * 使用条款和隐私策略
 */
public class BaseWebViewActivity extends BaseActivity {
  public static final String INTENT_URL = "INTENT_URL";
  public static final String INTENT_TITLE = "INTENT_TITLE";
  public static final String INTENT_BGRES_ID = "INTENT_BGRES_ID";

  @BindView(R2.id.webView) ProgressWebView webView;
  @BindView(R2.id.lh_tv_title) TextView lhTvTitle;
  @BindView(R2.id.ll_back) LinearLayout llBack;
  @BindView(R2.id.layout_head) RelativeLayout layoutHead;
  @BindView(R2.id.tv_left) TextView tvLeft;

  private String url, titlename;
  private int bgResID;

  @Override public void setContentView() {
    setContentView(R.layout.library_activity_clause_tactics);
  }

  @Override public void init() {
    url = getIntent().getStringExtra(INTENT_URL);
    bgResID = getIntent().getIntExtra(INTENT_BGRES_ID, -1);
    if(bgResID > 0){
      layoutHead.setBackgroundResource(bgResID);
    }

    if (!isNetworkAvailable(mContext)) {
      ToastUtil.showNetErrorMessage(mContext);
      return;
    }
    titlename = getIntent().getStringExtra(INTENT_TITLE) == null ? ""
        : getIntent().getStringExtra(INTENT_TITLE);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setAppCacheEnabled(false);
    webView.loadUrl(url);

    llBack.setVisibility(View.VISIBLE);
    lhTvTitle.setText(titlename);
  }

  @OnClick(R2.id.ll_back) public void onViewClicked() {
    finish();
  }
}
